/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.passport.service.plugins  
 */
package com.apache.passport.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.passport.entity.BlackRoster;
import com.apache.passport.manager.BlackRosterManager;

/**
 * description:  判断黑名单中是否已经存在当前要存储的IP
 * @author Hou Dayu 创建时间：2014-12-24  
 * @Copyright(c)2014:
 */
public class ContainsIpPlugin implements PluginConnector {
	protected IDao blackRosterDao;
	private BlackRosterManager blackRosterManager;

	public void setUctUserDao(IDao blackRosterDao) {
		this.blackRosterDao = blackRosterDao;
	}

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public Object execute(ParamsVo arg0) throws Exception {
		BlackRoster blackRoster = (BlackRoster) getInfoByIp(arg0);
		if (!Validator.isEmpty(blackRoster)) {
			return true;
		}
		return false;
	}

	public void setBlackRosterManager(BlackRosterManager blackRosterManager) {
		this.blackRosterManager = blackRosterManager;
	}

	public Object getInfoByIp(ParamsVo<BlackRoster> vo) {
		String brIpaddress = (String) vo.getParams("brIpaddress");
		if (Validator.isNull(brIpaddress)) {
			return null;
		}
		String sql = blackRosterDao.getSql(3);
		MethodParam param = new MethodParam("ByIp", "", sql, "com.apache.passport.entity.BlackRoster");
		param.setParams("brIpaddress", brIpaddress);
		return blackRosterDao.selectSingle(param);
	}
}
